SWING |
您所在的位置:网站首页 › java component大小和首选大小 › SWING |
❮ 上一节
下一节 ❯
SWING - Component 组件类
简介
Component 组件类是 AWT 的非菜单用户界面控件的抽象基类。 组件表示具有图形表示的对象。 类声明以下是 java.awt.Component 类的声明 − public abstract class Component extends Object implements ImageObserver, MenuContainer, Serializable 字段以下是 java.awt.Component 类的字段 − static float BOTTOM_ALIGNMENT − getAlignmentY 易于使用的常量。 static float CENTER_ALIGNMENT − getAlignmentY 和 getAlignmentX 的易用常量。 static float LEFT_ALIGNMENT − getAlignmentX 的易用常量。 static float RIGHT_ALIGNMENT − getAlignmentX 的易用常量。 static float TOP_ALIGNMENT − getAlignmentY() 的易用常量。 类构造函数 S.No. 构造函数 & 描述 1protected Component() 这将创建一个新组件。 类方法 序号 方法 & 描述 1boolean action(Event evt, Object what) 已弃用。 从 JDK 1.1 版开始,应该将此组件注册为触发动作事件的组件上的 ActionListener。 2void add(PopupMenu popup) 将指定的弹出菜单添加到组件。 3void addComponentListener(ComponentListener l) 添加指定的组件侦听器以接收来自该组件的组件事件。 4void addFocusListener(FocusListener l) 当此组件获得输入焦点时,添加指定的焦点侦听器以接收来自此组件的焦点事件。 5void addHierarchyBoundsListener(HierarchyBoundsListener l) 当该容器所属的层次结构发生变化时,添加指定的层次边界侦听器以接收来自该组件的层次边界事件。 6void addHierarchyListener(HierarchyListener l) 当此容器所属的层次结构发生更改时,添加指定的层次结构侦听器以接收来自此组件的层次结构更改事件。 7void addInputMethodListener(InputMethodListener l) 添加指定的输入法侦听器以接收来自该组件的输入法事件。 8void addKeyListener(KeyListener l) 添加指定的按键侦听器以接收来自该组件的按键事件。 9void addMouseListener(MouseListener l) 添加指定的鼠标侦听器以接收来自该组件的鼠标事件。 10void addMouseMotionListener(MouseMotionListener l) 添加指定的鼠标运动侦听器以接收来自该组件的鼠标运动事件。 11void addMouseWheelListener(MouseWheelListener l) 添加指定的鼠标滚轮侦听器以接收来自该组件的鼠标滚轮事件。 12void addNotify() 通过将其连接到本机屏幕资源,使该组件可显示。 13void addPropertyChangeListener(PropertyChangeListener listener) 将 PropertyChangeListener 添加到侦听器列表中。 14void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) 将 PropertyChangeListener 添加到特定属性的侦听器列表中。 15void applyComponentOrientation(ComponentOrientation orientation) 设置此组件和其中包含的所有组件的 ComponentOrientation 属性。 16boolean areFocusTraversalKeysSet(int id) 返回给定焦点遍历操作的焦点遍历键集是否已为此组件显式定义。 17int checkImage(Image image, ImageObserver observer) 返回指定图像的屏幕表示的构造状态。 18int checkImage(Image image,int width,int height, ImageObserver observer) 返回指定图像的屏幕表示的构造状态。 19boolean contains(int x,int y) 检查此组件是否"包含"指定点,其中 x 和 y 被定义为相对于该组件的坐标系。 20boolean contains(Point p) 检查此组件是否"包含"指定点,其中点的 x 和 y 坐标定义为相对于该组件的坐标系。 21Image createImage(ImageProducer producer) 从指定的图像生成器创建图像。 22Image createImage(int width,int height) 创建用于双缓冲的离屏可绘制图像。 23VolatileImage createVolatileImage(int width,int height) 创建一个不稳定的屏幕外可绘制图像以用于双缓冲。 24VolatileImage createVolatileImage(int width,int height, ImageCapabilities caps) 使用给定的功能创建一个不稳定的离屏可绘制图像。 25void deliverEvent(Event e) 已弃用。 从 JDK 1.1 版本开始,由 dispatchEvent(AWTEvent e) 取代。 26void disable() 已弃用。 从 JDK 版本 1.1 开始,由 setEnabled(boolean) 取代。 27protected void disableEvents(long eventsToDisable) 禁止将指定事件掩码参数定义的事件传递给该组件。 28void dispatchEvent(AWTEvent e) 向该组件或其子组件之一分派事件。 29void doLayout() 提示布局管理器布局此组件。 30void enable() 已弃用。 从 JDK 版本 1.1 开始,由 setEnabled(boolean) 取代。 31void enable(boolean b) 已弃用。 从 JDK 版本 1.1 开始,由 setEnabled(boolean) 取代。 32protected void enableEvents(long eventsToEnable) 允许将指定的事件掩码参数定义的事件传递给该组件。 33void enableInputMethods(boolean enable) 启用或禁用此组件的输入法支持。 34protected void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) 支持报告布尔属性的绑定属性更改。 35void firePropertyChange(String propertyName, byte oldValue, byte newValue) 报告绑定的属性更改。 36void firePropertyChange(String propertyName, char oldValue, char newValue) 报告绑定的属性更改。 37void firePropertyChange(String propertyName, double oldValue, double newValue) 报告绑定的属性更改。 38void firePropertyChange(String propertyName, float oldValue, float newValue) 报告绑定的属性更改。 39void firePropertyChange(String propertyName, long oldValue, long newValue) 报告绑定的属性更改。 40protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) 支持报告对象属性的绑定属性更改。 41void firePropertyChange(String propertyName, short oldValue, short newValue) 报告绑定的属性更改。 42AccessibleContext getAccessibleContext() 获取与此组件关联的 AccessibleContext。 43float getAlignmentX() 返回沿 x 轴的对齐方式。 44float getAlignmentY() 返回沿 y 轴的对齐方式。 45Color getBackground() 获取此组件的背景颜色。 46int getBaseline(int width,int height) 返回基线。 47Component.BaselineResizeBehavior getBaselineResizeBehavior() 返回一个枚举,指示组件的基线如何随着大小的变化而变化。 48Rectangle getBounds() 以 Rectangle 对象的形式获取此组件的边界。 49Rectangle getBounds(Rectangle rv) 将此组件的边界存储到"返回值"rv 中并返回 rv。 50ColorModel getColorModel() 获取用于在输出设备上显示组件的 ColorModel 实例。 51Component getComponentAt(int x,int y) 确定此组件或其直接子组件之一是否包含 (x, y) 位置,如果是,则返回包含组件。 52Component getComponentAt(Point p) 返回包含指定点的组件或子组件。 53ComponentListener[] getComponentListeners() 返回在此组件上注册的所有组件侦听器的数组。 54ComponentOrientation getComponentOrientation() 检索用于对该组件中的元素或文本进行排序的语言敏感方向。 55Cursor getCursor() 获取组件中设置的光标。 56DropTarget getDropTarget() 获取与此 Component 关联的 DropTarget。 57Container getFocusCycleRootAncestor() 返回 Container,它是该组件的焦点遍历循环的焦点循环根。 58FocusListener[] getFocusListeners() 返回在此组件上注册的所有焦点侦听器的数组。 59Set getFocusTraversalKeys(int id) 返回此组件的给定遍历操作的焦点遍历键集。 60boolean getFocusTraversalKeysEnabled() 返回是否为此组件启用焦点遍历键。 61Font getFont() 获取该组件的字体。 62FontMetrics getFontMetrics(Font font) 获取指定字体的字体规格。 63Color getForeground() 获取该组件的前景色。 64Graphics getGraphics() 为此组件创建图形上下文。 65GraphicsConfiguration getGraphicsConfiguration() 获取与此 Component 关联的 GraphicsConfiguration。 66int getHeight() 返回此组件的当前高度。 67HierarchyBoundsListener[] getHierarchyBoundsListeners() 返回在此组件上注册的所有层次边界侦听器的数组。 68HierarchyListener[] getHierarchyListeners() 返回在此组件上注册的所有层次结构侦听器的数组。 69boolean getIgnoreRepaint() 70InputContext getInputContext() 当在此组件中输入文本时,获取此组件用于处理与输入法的通信的输入上下文。 71InputMethodListener[] getInputMethodListeners() 返回在此组件上注册的所有输入法侦听器的数组。 72InputMethodRequests getInputMethodRequests() 获取支持来自此组件的输入法请求的输入法请求处理程序。 73KeyListener[] getKeyListeners() 返回在此组件上注册的所有键侦听器的数组。 74T[] getListeners(Class listenerType) 返回当前在此组件上注册为 FooListeners 的所有对象的数组。 75Locale getLocale() 获取此组件的语言环境。 76Point getLocation() 以指定组件左上角的点的形式获取此组件的位置。 77Point getLocation(Point rv) 将此组件的 x,y 原点存储到"返回值"rv 中并返回 rv。 78Point getLocationOnScreen() 以点的形式获取此组件的位置,该点指定组件在屏幕坐标空间中的左上角。 79Dimension getMaximumSize() 获取此组件的最大大小。 80Dimension getMinimumSize() 获取此组件的最小尺寸。 81MouseListener[] getMouseListeners() 返回在此组件上注册的所有鼠标侦听器的数组。 82MouseMotionListener[] getMouseMotionListeners() 返回在此组件上注册的所有鼠标运动侦听器的数组。 83Point getMousePosition() 如果 Component 在鼠标指针正下方,则返回鼠标指针在此 Component 坐标空间中的位置,否则返回 null。 84MouseWheelListener[] getMouseWheelListeners() 返回在此组件上注册的所有鼠标滚轮侦听器的数组。 85String getName() 获取组件的名称。 86Container getParent() 获取此组件的父级。 87java.awt.peer.ComponentPeer getPeer() 已弃用。 从 JDK 1.1 版开始,程序不应直接操作对等点; 替换为布尔 isDisplayable()。 88Dimension getPreferredSize() 获取此组件的首选大小。 89PropertyChangeListener[] getPropertyChangeListeners() 返回在此组件上注册的所有属性更改侦听器的数组。 90PropertyChangeListener[] getPropertyChangeListeners(String propertyName) 返回与命名属性关联的所有侦听器的数组。 91Dimension getSize() 以 Dimension 对象的形式返回此组件的大小。 92Dimension getSize(Dimension rv) 将此组件的宽度/高度存储到"返回值:rv 并返回 rv. 93Toolkit getToolkit() 获取该组件的工具包。 94Object getTreeLock() 为 AWT 组件树和布局操作获取此组件锁定对象(拥有线程同步监视器的对象)。 95int getWidth() 返回此组件的当前宽度。 96int getX() 返回组件原点的当前 x 坐标。 97int getY() 返回组件原点的当前 y 坐标。 98boolean gotFocus(Event evt, Object what) 已弃用。 从 JDK 1.1 版开始,由 processFocusEvent(FocusEvent) 取代。 99boolean handleEvent(Event evt) 已弃用。 从 JDK 1.1 版开始,由 processEvent(AWTEvent) 取代。 100boolean hasFocus() 如果此 Component 是焦点所有者,则返回 true。 101void hide() 已弃用。 从 JDK 版本 1.1 开始,由 setVisible(boolean) 取代。 102boolean imageUpdate(Image img,int infoflags,int x,int y,int w,int h) 当图像改变时重绘组件。 103boolean inside(int x,int y) 已弃用。 从 JDK 1.1 版开始,由 contains(int, int) 取代。 104void invalidate() 使该组件无效。 105boolean isBackgroundSet() 返回是否已为此组件显式设置背景颜色。 106boolean isCursorSet() 返回是否已为此组件显式设置光标。 107boolean isDisplayable() 确定此组件是否可显示。 108boolean isDoubleBuffered() 如果将此组件绘制到稍后复制到屏幕的离屏图像(缓冲区),则返回 true。 109boolean isEnabled() 确定是否启用此组件。 110boolean isFocusable() 返回此 Component 是否可以聚焦。 111boolean isFocusCycleRoot(Container container) 返回指定的 Container 是否为本 Component 的焦点遍历循环的焦点循环根。 112boolean isFocusOwner() 如果此 Component 是焦点所有者,则返回 true。 113boolean isFocusTraversable() 已弃用。 从 1.4 开始,由 isFocusable() 取代。 114boolean isFontSet() 返回是否已为此组件显式设置字体。 115boolean isForegroundSet() 返回是否已为此组件显式设置前景色。 116boolean isLightweight() 轻量级组件没有原生工具包对等体。 117boolean isMaximumSizeSet() 如果最大大小已设置为非空值,则返回 true,否则返回 false。 118boolean isMinimumSizeSet() 返回是否已使用非空值调用 setMinimumSize。 119boolean isOpaque() 如果此组件完全不透明,则返回 true,默认返回 false。 120boolean isPreferredSizeSet() 如果首选大小已设置为非空值,则返回 true,否则返回 false。 121boolean isShowing() 确定此组件是否显示在屏幕上。 122boolean isValid() 确定此组件是否有效。 123boolean isVisible() 确定此组件在其父组件可见时是否应该可见。 124boolean keyDown(Event evt,int key) 已弃用。 从 JDK 1.1 版开始,由 processKeyEvent(KeyEvent) 取代。 125boolean keyUp(Event evt,int key) 已弃用。 从 JDK 1.1 版开始,由 processKeyEvent(KeyEvent) 取代。 126void layout() 已弃用。 从 JDK 1.1 版开始,由 doLayout() 取代。 127void list() 将此组件的列表打印到标准系统输出流 System.out。 128void list(PrintStream out) 将此组件的列表打印到指定的输出流。 129void list(PrintStream out,int indent) 从指定的缩进开始,将列表打印到指定的打印流。 130void list(PrintWriter out) 将列表打印到指定的打印作者。 131void list(PrintWriter out,int indent) 从指定的缩进开始,将列表打印到指定的打印写入器。 132Component locate(int x,int y) 已弃用。 从 JDK 1.1 版开始,由 getComponentAt(int, int) 取代。 133Point location() 已弃用。 从 JDK 版本 1.1 开始,由 getLocation() 取代。 134boolean lostFocus(Event evt, Object what) 已弃用。 从 JDK 版本 1.1 开始,由 processFocusEvent(FocusEvent) 取代。 135boolean mouseDown(Event evt,int x,int y) 已弃用。 从 JDK 版本 1.1 开始,由 processMouseEvent(MouseEvent) 取代。 136boolean mouseDrag(Event evt,int x,int y) 已弃用。 从 JDK 版本 1.1 开始,由 processMouseMotionEvent(MouseEvent) 取代。 137boolean mouseEnter(Event evt,int x,int y) 已弃用。 从 JDK 版本 1.1 开始,由 processMouseEvent(MouseEvent) 取代。 138boolean mouseExit(Event evt,int x,int y) 已弃用。 从 JDK 版本 1.1 开始,由 processMouseEvent(MouseEvent) 取代。 139boolean mouseMove(Event evt,int x,int y) 已弃用。 从 JDK 版本 1.1 开始,由 processMouseMotionEvent(MouseEvent) 取代。 140boolean mouseUp(Event evt,int x,int y) 已弃用。 从 JDK 版本 1.1 开始,由 processMouseEvent(MouseEvent) 取代。 141void move(int x,int y) 已弃用。 从 JDK 版本 1.1 开始,由 setLocation(int, int) 取代。 142void nextFocus() 已弃用。 从 JDK 版本 1.1 开始,由 transferFocus() 取代。 143void paint(Graphics g) 绘制此组件。 144void paintAll(Graphics g) 绘制此组件及其所有子组件。 145boolean postEvent(Event e) 已弃用。 从 JDK 版本 1.1 开始,由 dispatchEvent(AWTEvent) 取代。 146boolean prepareImage(Image image,int width,int height, ImageObserver observer) 准备在此组件上以指定宽度和高度呈现的图像。 147void print(Graphics g) 打印此组件。 148void printAll(Graphics g) 打印此组件及其所有子组件。 149protectedvoid processComponentEvent(ComponentEvent e) 通过将在此组件上发生的组件事件分派到任何已注册的 ComponentListener 对象来处理它们。 150protected void processEvent(AWTEvent e) 处理此组件上发生的事件。 151protected void processFocusEvent(FocusEvent e) 通过将在此组件上发生的焦点事件分派给任何已注册的 FocusListener 对象来处理它们。 152protected void processHierarchyBoundsEvent(HierarchyEvent e) 通过将在此组件上发生的层次结构边界事件分派到任何已注册的 HierarchyBoundsListener 对象来处理它们。 153protected void processHierarchyEvent(HierarchyEvent e) 通过将在此组件上发生的层次结构事件分派给任何已注册的 HierarchyListener 对象来处理它们。 154protectedvoid processInputMethodEvent(InputMethodEvent e) 通过将在此组件上发生的输入法事件分派到任何已注册的 InputMethodListener 对象来处理它们。 155protected void processKeyEvent(KeyEvent e) 通过将在此组件上发生的关键事件分派给任何已注册的 KeyListener 对象来处理它们。 156protected void processMouseEvent(MouseEvent e) 通过将鼠标事件分派到任何已注册的 MouseListener 对象来处理此组件上发生的鼠标事件。 157protected void processMouseMotionEvent(MouseEvent e) 通过将在此组件上发生的鼠标运动事件分派给任何已注册的 MouseMotionListener 对象来处理它们。 158protected void processMouseWheelEvent(MouseWheelEvent e) 通过将鼠标滚轮事件分派到任何已注册的 MouseWheelListener 对象来处理此组件上发生的鼠标滚轮事件。 159void remove(MenuComponent popup) 从组件中移除指定的弹出菜单。 160void removeComponentListener(ComponentListener l) 移除指定的组件侦听器,使其不再接收来自该组件的组件事件。 161void removeFocusListener(FocusListener l) 移除指定的焦点侦听器,使其不再接收来自该组件的焦点事件。 162void removeHierarchyBoundsListener(HierarchyBoundsListener l) 移除指定的层次边界侦听器,使其不再接收来自该组件的层次边界事件。 163void removeHierarchyListener(HierarchyListener l) 删除指定的层次结构侦听器,使其不再接收来自该组件的层次结构更改事件。 164void removeInputMethodListener(InputMethodListener l) 移除指定的输入法侦听器,使其不再接收来自该组件的输入法事件。 165void removeKeyListener(KeyListener l) 移除指定的按键监听器,使其不再接收来自该组件的按键事件。 166void removeMouseListener(MouseListener l) 移除指定的鼠标侦听器,使其不再接收来自该组件的鼠标事件。 167void removeMouseMotionListener(MouseMotionListener l) 移除指定的鼠标运动侦听器,使其不再接收来自该组件的鼠标运动事件。 168void removeMouseWheelListener(MouseWheelListener l) 移除指定的鼠标滚轮侦听器,使其不再接收来自该组件的鼠标滚轮事件。 169void removeNotify() 通过破坏其本机屏幕资源使该组件无法显示。 170void removePropertyChangeListener(PropertyChangeListener listener) 从侦听器列表中移除一个 PropertyChangeListener。 171void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) 从特定属性的侦听器列表中移除 PropertyChangeListener。 172void repaint() 重绘此组件。 173void repaint(int x,int y,int width,int height) 重绘该组件的指定矩形。 174void repaint(long tm) 重绘组件。 175void repaint(long tm,int x,int y,int width,int height) 在 tm 毫秒内重新绘制此组件的指定矩形。 176void requestFocus() 请求该组件获得输入焦点,并且该组件的顶级祖先成为焦点窗口。 177protected boolean requestFocus(boolean temporary) 请求该组件获得输入焦点,并且该组件的顶级祖先成为焦点窗口。 178boolean requestFocusInWindow() 如果该组件的顶级祖先已经是焦点窗口,则请求该组件获得输入焦点。 179protected boolean requestFocusInWindow(boolean temporary) 如果该组件的顶级祖先已经是焦点窗口,则请求该组件获得输入焦点。 180void reshape(int x,int y,int width,int height) 已弃用。 从 JDK 版本 1.1 开始,由 setBounds(int, int, int, int) 取代。 181void resize(Dimension d) 已弃用。 从 JDK 1.1 版开始,由 setSize(Dimension) 取代。 182void resize(int width,int height) 已弃用。 从 JDK 版本 1.1 开始,由 setSize(int, int) 取代。 183void setBackground(Color c) 设置此组件的背景颜色。 184void setBounds(int x,int y,int width,int height) 移动此组件并调整其大小。 185void setBounds(Rectangle r) 移动该组件并调整其大小以符合新的边界矩形 r。 186void setComponentOrientation(ComponentOrientation o) 设置用于对该组件中的元素或文本进行排序的语言敏感方向。 187void setCursor(Cursor cursor) 将光标图像设置为指定的光标。 188void setDropTarget(DropTarget dt) 将 DropTarget 与此组件相关联。 189void setEnabled(boolean b) 根据参数 b 的值启用或禁用此组件。 190void setFocusable(boolean focusable) 将此组件的可聚焦状态设置为指定值。 191void setFocusTraversalKeys(int id, Set |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |